package org.sidora.strata.site;


import java.awt.event.ActionEvent;
import java.io.Serializable;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.TreeSet;
import java.util.logging.Level;
import javax.swing.DefaultListModel;
import javax.swing.JList;
import javax.swing.UIManager;
import org.openide.ErrorManager;
import org.openide.util.NbBundle;
import org.openide.util.Utilities;
import org.openide.windows.TopComponent;
import org.openide.windows.WindowManager;
import org.sidora.core.Action;
import org.sidora.core.Dating;
import org.sidora.core.Phase;
import org.sidora.core.Site;
import org.sidora.core.Zone;
import org.sidora.core.util.AbstractInventory;
import org.sidora.core.util.LoggerProvider;
import org.sidora.core.util.ParameterCollector;
import org.sidora.strata.Storage;



/**
 * Top component which displays something.
 * @author Enric Tartera, Juan Manuel Gimeno, Roger Masgoret
 * @version 1.0
 */
final class SiteFormTopComponent extends TopComponent {
    
    private static SiteFormTopComponent instance;
    /** path to the icon used by the component and its open action */
    static final String ICON_PATH = "org/sidora/resources/site16.png";
    
    private static final String PREFERRED_ID = "SiteFormTopComponent";
    
    private SiteFormTopComponent() {
        System.setProperty(
            "Quaqua.tabLayoutPolicy","wrap"
         );
         // set the Quaqua Look and Feel in the UIManager
         try { 
              UIManager.setLookAndFeel(
                  "ch.randelshofer.quaqua.QuaquaLookAndFeel"
              );
         // set UI manager properties here that affect Quaqua
         
         } catch (Exception e) {
             // take an appropriate action here
             
         }
        initComponents();
        setName(NbBundle.getMessage(SiteFormTopComponent.class, "CTL_SiteFormTopComponent"));
        setToolTipText(NbBundle.getMessage(SiteFormTopComponent.class, "HINT_SiteFormTopComponent"));
        setIcon(Utilities.loadImage(ICON_PATH, true));
    

    
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane2 = new javax.swing.JScrollPane();
        jTextAreaDescription = new javax.swing.JTextArea();
        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jTextFieldId = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jTextFieldName = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jTextFieldAcronym = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jTextFieldAbbreviation = new javax.swing.JTextField();
        jPanel2 = new javax.swing.JPanel();
        jLabel5 = new javax.swing.JLabel();
        jTextFieldToponym = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jTextFieldTown = new javax.swing.JTextField();
        jTextFieldArea = new javax.swing.JTextField();
        jTextFieldRegion = new javax.swing.JTextField();
        jTextFieldCountry = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        jPanel3 = new javax.swing.JPanel();
        jScrollPane4 = new javax.swing.JScrollPane();
        jListZones = new javax.swing.JList();
        jListZones.putClientProperty(

            "Quaqua.List.style", "striped"

        );
        jButtonDelZones = new javax.swing.JButton();
        jButtonDelZones.putClientProperty(

            "Quaqua.Button.style", "placard"

        );
        jButtonAddZones = new javax.swing.JButton();
        jButtonAddZones.putClientProperty(

            "Quaqua.Button.style", "placard"

        );
        jPanel4 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jListSites = new javax.swing.JList();
        jListSites.putClientProperty(

            "Quaqua.List.style", "striped"

        );
        jButtonAddSite1 = new javax.swing.JButton();
        jButtonAddSite1.putClientProperty(

            "Quaqua.Button.style", "placard"

        );
        jButtonAddSite = new javax.swing.JButton();
        jButtonAddSite.putClientProperty(

            "Quaqua.Button.style", "placard"

        );
        jButtonDelSite = new javax.swing.JButton();
        jButtonDelSite.putClientProperty(

            "Quaqua.Button.style", "placard"

        );
        jPanel5 = new javax.swing.JPanel();
        jScrollPane3 = new javax.swing.JScrollPane();
        jListPhases = new javax.swing.JList();
        jListPhases.putClientProperty(

            "Quaqua.List.style", "striped"

        );
        jButtonAddPhases = new javax.swing.JButton();
        jButtonAddPhases.putClientProperty(

            "Quaqua.Button.style", "placard"

        );
        jButtonDelPhases = new javax.swing.JButton();
        jButtonDelPhases.putClientProperty(

            "Quaqua.Button.style", "placard"

        );
        jPanel6 = new javax.swing.JPanel();
        jScrollPane5 = new javax.swing.JScrollPane();
        jListActions = new javax.swing.JList();
        jListActions.putClientProperty(

            "Quaqua.List.style", "striped"

        );
        jButtonAddActions = new javax.swing.JButton();
        jButtonAddActions.putClientProperty(

            "Quaqua.Button.style", "placard"

        );
        jButtonDelActions = new javax.swing.JButton();
        jButtonDelActions.putClientProperty(

            "Quaqua.Button.style", "placard"

        );

        jTextAreaDescription.setBackground(new java.awt.Color(250, 240, 200));
        jTextAreaDescription.setColumns(20);
        jTextAreaDescription.setFont(new java.awt.Font("Georgia", 0, 13)); // NOI18N
        jTextAreaDescription.setLineWrap(true);
        jTextAreaDescription.setRows(5);
        jTextAreaDescription.setWrapStyleWord(true);
        jTextAreaDescription.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                jTextAreaDescriptionFocusLost(evt);
            }
        });
        jScrollPane2.setViewportView(jTextAreaDescription);

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Identity"));

        org.openide.awt.Mnemonics.setLocalizedText(jLabel1, "Id:");

        org.openide.awt.Mnemonics.setLocalizedText(jLabel2, "Acronym:");

        jTextFieldName.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                jTextFieldNameFocusLost(evt);
            }
        });

        org.openide.awt.Mnemonics.setLocalizedText(jLabel3, "Name:");

        jTextFieldAcronym.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                jTextFieldAcronymFocusLost(evt);
            }
        });

        org.openide.awt.Mnemonics.setLocalizedText(jLabel4, "Abbreviation:");

        jTextFieldAbbreviation.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                jTextFieldAbbreviationFocusLost(evt);
            }
        });

        org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                    .add(jLabel1)
                    .add(jLabel3)
                    .add(jLabel2))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jPanel1Layout.createSequentialGroup()
                        .add(jTextFieldAcronym, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 37, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jLabel4)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jTextFieldAbbreviation, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 86, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                    .add(jTextFieldName, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 301, Short.MAX_VALUE)
                    .add(jTextFieldId, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 78, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel1Layout.createSequentialGroup()
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jTextFieldId, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jLabel1))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jTextFieldName, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jLabel3))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jTextFieldAcronym, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jLabel4)
                    .add(jTextFieldAbbreviation, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jLabel2))
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Localization"));

        org.openide.awt.Mnemonics.setLocalizedText(jLabel5, "Toponym:");

        jTextFieldToponym.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                jTextFieldToponymFocusLost(evt);
            }
        });

        org.openide.awt.Mnemonics.setLocalizedText(jLabel6, "Town:");

        org.openide.awt.Mnemonics.setLocalizedText(jLabel7, "Area:");

        org.openide.awt.Mnemonics.setLocalizedText(jLabel8, "Region:");

        org.openide.awt.Mnemonics.setLocalizedText(jLabel9, "Country:");

        jTextFieldTown.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                jTextFieldTownFocusLost(evt);
            }
        });

        jTextFieldArea.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                jTextFieldAreaFocusLost(evt);
            }
        });

        jTextFieldRegion.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                jTextFieldRegionFocusLost(evt);
            }
        });

        jTextFieldCountry.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                jTextFieldCountryFocusLost(evt);
            }
        });

        org.jdesktop.layout.GroupLayout jPanel2Layout = new org.jdesktop.layout.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                    .add(jLabel6)
                    .add(jLabel5)
                    .add(jLabel7)
                    .add(jLabel8)
                    .add(jLabel9))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jTextFieldToponym, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 297, Short.MAX_VALUE)
                    .add(jTextFieldTown, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 297, Short.MAX_VALUE)
                    .add(jTextFieldArea, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 297, Short.MAX_VALUE)
                    .add(jTextFieldRegion, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 297, Short.MAX_VALUE)
                    .add(jTextFieldCountry, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 297, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel2Layout.createSequentialGroup()
                .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jTextFieldToponym, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jLabel5))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jTextFieldTown, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jLabel6))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jTextFieldArea, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jLabel7))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jTextFieldRegion, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jLabel8))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jTextFieldCountry, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jLabel9)))
        );

        org.openide.awt.Mnemonics.setLocalizedText(jLabel10, "Description");

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Zones:"));

        jScrollPane4.setViewportView(jListZones);

        org.openide.awt.Mnemonics.setLocalizedText(jButtonDelZones, "-");
        jButtonDelZones.setMargin(new java.awt.Insets(2, 2, 2, 2));

        org.openide.awt.Mnemonics.setLocalizedText(jButtonAddZones, "+");
        jButtonAddZones.setMargin(new java.awt.Insets(2, 2, 2, 2));

        org.jdesktop.layout.GroupLayout jPanel3Layout = new org.jdesktop.layout.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, jScrollPane4, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 250, Short.MAX_VALUE)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .add(jButtonDelZones, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 28, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jButtonAddZones, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 28, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel3Layout.createSequentialGroup()
                .add(jScrollPane4, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jButtonAddZones)
                    .add(jButtonDelZones)))
        );

        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder("Sites:"));

        jListSites.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
            public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
                jListSitesValueChanged(evt);
            }
        });
        jScrollPane1.setViewportView(jListSites);

        org.openide.awt.Mnemonics.setLocalizedText(jButtonAddSite1, "<");
        jButtonAddSite1.setMargin(new java.awt.Insets(2, 2, 2, 2));
        jButtonAddSite1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonAddSite1ActionPerformed(evt);
            }
        });

        org.openide.awt.Mnemonics.setLocalizedText(jButtonAddSite, "+");
        jButtonAddSite.setMargin(new java.awt.Insets(2, 2, 2, 2));
        jButtonAddSite.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonAddSiteActionPerformed(evt);
            }
        });

        org.openide.awt.Mnemonics.setLocalizedText(jButtonDelSite, "-");
        jButtonDelSite.setMargin(new java.awt.Insets(2, 2, 2, 2));
        jButtonDelSite.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonDelSiteActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout jPanel4Layout = new org.jdesktop.layout.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .add(jButtonAddSite1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 35, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jButtonAddSite, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 35, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jButtonDelSite, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 35, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
            .add(org.jdesktop.layout.GroupLayout.TRAILING, jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 229, Short.MAX_VALUE)
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel4Layout.createSequentialGroup()
                .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 284, Short.MAX_VALUE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel4Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jButtonDelSite)
                    .add(jButtonAddSite)
                    .add(jButtonAddSite1)))
        );

        jPanel5.setBorder(javax.swing.BorderFactory.createTitledBorder("Phases:"));

        jListPhases.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
            public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
                jListPhasesValueChanged(evt);
            }
        });
        jScrollPane3.setViewportView(jListPhases);

        org.openide.awt.Mnemonics.setLocalizedText(jButtonAddPhases, "+");
        jButtonAddPhases.setMargin(new java.awt.Insets(2, 2, 2, 2));
        jButtonAddPhases.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonAddPhasesActionPerformed(evt);
            }
        });

        org.openide.awt.Mnemonics.setLocalizedText(jButtonDelPhases, "-");
        jButtonDelPhases.setMargin(new java.awt.Insets(2, 2, 2, 2));
        jButtonDelPhases.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonDelPhasesActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout jPanel5Layout = new org.jdesktop.layout.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, jScrollPane3, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 250, Short.MAX_VALUE)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .add(jButtonAddPhases, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 28, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jButtonDelPhases, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 28, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel5Layout.createSequentialGroup()
                .add(jScrollPane3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 109, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel5Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jButtonDelPhases)
                    .add(jButtonAddPhases)))
        );

        jPanel6.setBorder(javax.swing.BorderFactory.createTitledBorder("Actions"));

        jListActions.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
            public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
                jListActionsValueChanged(evt);
            }
        });
        jScrollPane5.setViewportView(jListActions);

        org.openide.awt.Mnemonics.setLocalizedText(jButtonAddActions, "+");
        jButtonAddActions.setMargin(new java.awt.Insets(2, 2, 2, 2));
        jButtonAddActions.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonAddActionsActionPerformed(evt);
            }
        });

        org.openide.awt.Mnemonics.setLocalizedText(jButtonDelActions, "-");
        jButtonDelActions.setMargin(new java.awt.Insets(2, 2, 2, 2));
        jButtonDelActions.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonDelActionsActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout jPanel6Layout = new org.jdesktop.layout.GroupLayout(jPanel6);
        jPanel6.setLayout(jPanel6Layout);
        jPanel6Layout.setHorizontalGroup(
            jPanel6Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, jScrollPane5, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 250, Short.MAX_VALUE)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel6Layout.createSequentialGroup()
                .addContainerGap()
                .add(jButtonAddActions, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 28, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jButtonDelActions, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 28, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
        );
        jPanel6Layout.setVerticalGroup(
            jPanel6Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(jPanel6Layout.createSequentialGroup()
                .add(jScrollPane5, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 152, Short.MAX_VALUE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jPanel6Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jButtonAddActions)
                    .add(jButtonDelActions)))
        );

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(layout.createSequentialGroup()
                        .add(jPanel4, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                            .add(layout.createSequentialGroup()
                                .add(1, 1, 1)
                                .add(jPanel2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                            .add(jPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                    .add(jLabel10)
                    .add(jScrollPane2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 664, Short.MAX_VALUE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                    .add(jPanel3, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .add(jPanel5, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .add(jPanel6, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(layout.createSequentialGroup()
                        .add(jPanel3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .add(17, 17, 17)
                        .add(jPanel5, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                        .add(jPanel6, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .add(layout.createSequentialGroup()
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false)
                            .add(org.jdesktop.layout.GroupLayout.LEADING, jPanel4, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .add(org.jdesktop.layout.GroupLayout.LEADING, layout.createSequentialGroup()
                                .add(jPanel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                                .add(jPanel2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jLabel10)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jScrollPane2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 236, Short.MAX_VALUE)))
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents
    
    private void jButtonDelActionsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonDelActionsActionPerformed
        removeAction();
    }//GEN-LAST:event_jButtonDelActionsActionPerformed
    
    private void jButtonDelPhasesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonDelPhasesActionPerformed
        removePhase();
    }//GEN-LAST:event_jButtonDelPhasesActionPerformed
    
    protected void removePhase() {
        
        //Recupera l'element seleccionat
        Phase phase = (Phase) jListPhases.getSelectedValue();
        
        AbstractInventory.deleteObject(phase);
        
        fillPhaseList();
        
        Storage.getPhaseFormAction().clearFields();
    }
    
    protected void removeAction() {
        
        Action action = (Action) jListActions.getSelectedValue();
        
        if(action != null){
            AbstractInventory.deleteObject(action);
            fillActionList();
            Storage.getActionFormAction().clearFields();
        }
    }
   
    private void jListActionsValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_jListActionsValueChanged
        
            if (jListActions.getSelectedValue() instanceof Action){
                Storage.getActionFormAction().actionPerformed((Action)jListActions.getSelectedValue());
            }
        
    }//GEN-LAST:event_jListActionsValueChanged
    
    private void jButtonAddActionsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonAddActionsActionPerformed
        addAction();
        fillActionList();
    }//GEN-LAST:event_jButtonAddActionsActionPerformed
    
    private void jListPhasesValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_jListPhasesValueChanged
        
            if (jListPhases.getSelectedValue() instanceof Phase){
                Storage.getPhaseFormAction().actionPerformed((Phase)jListPhases.getSelectedValue());
            }
      
    }//GEN-LAST:event_jListPhasesValueChanged
    
    private void jButtonAddPhasesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonAddPhasesActionPerformed
        addPhase();
        fillPhaseList();
    }//GEN-LAST:event_jButtonAddPhasesActionPerformed
    
    private void jButtonAddSite1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonAddSite1ActionPerformed
        if (this.site != null){
            fillSiteFields(this.site);
        }
    }//GEN-LAST:event_jButtonAddSite1ActionPerformed
    
    private void jButtonDelSiteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonDelSiteActionPerformed
        removeSite();
        fillSiteComboBox();
    }//GEN-LAST:event_jButtonDelSiteActionPerformed
    
    private void jTextAreaDescriptionFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jTextAreaDescriptionFocusLost
        saveAllData();
    }//GEN-LAST:event_jTextAreaDescriptionFocusLost
    
    private void jTextFieldCountryFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jTextFieldCountryFocusLost
        saveAllData();
    }//GEN-LAST:event_jTextFieldCountryFocusLost
    
    private void jTextFieldRegionFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jTextFieldRegionFocusLost
        saveAllData();
    }//GEN-LAST:event_jTextFieldRegionFocusLost
    
    private void jTextFieldAreaFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jTextFieldAreaFocusLost
        saveAllData();
    }//GEN-LAST:event_jTextFieldAreaFocusLost
    
    private void jTextFieldTownFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jTextFieldTownFocusLost
        saveAllData();
    }//GEN-LAST:event_jTextFieldTownFocusLost
    
    private void jTextFieldToponymFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jTextFieldToponymFocusLost
        saveAllData();
    }//GEN-LAST:event_jTextFieldToponymFocusLost
    
    private void jTextFieldAbbreviationFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jTextFieldAbbreviationFocusLost
        saveAllData();
    }//GEN-LAST:event_jTextFieldAbbreviationFocusLost
    
    private void jTextFieldAcronymFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jTextFieldAcronymFocusLost
        saveAllData();
    }//GEN-LAST:event_jTextFieldAcronymFocusLost
    
    private void jTextFieldNameFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_jTextFieldNameFocusLost
        saveAllData();
    }//GEN-LAST:event_jTextFieldNameFocusLost
    
    
    private void saveAllData(){
        if (this.site != null){
            
            Site site = this.site;
            site.setName(jTextFieldName.getText());
            site.setAbbreviation(jTextFieldAbbreviation.getText());
            site.setAcronyn(jTextFieldAcronym.getText());
            site.setArea(jTextFieldArea.getText());
            site.setCountry(jTextFieldCountry.getText());
            site.setDescription(jTextAreaDescription.getText());
            site.setRegion(jTextFieldRegion.getText());
            site.setToponym(jTextFieldToponym.getText());
            site.setTown(jTextFieldTown.getText());
            
            Site.Inventory.setObject(site);
        }
    }
    
    public void setSelectedSite(int i){
        jListSites.setSelectedIndex(i);
        showSelectedSite();
    }
    
    private void jListSitesValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_jListSitesValueChanged
        
            saveAllData();
            
            showSelectedSite();
            int iSite = jListSites.getSelectedIndex();
            Storage.getSiteNavigation().setSelectedSite(iSite);
            //Storage.getSiteNavigation().setSelectedSite(jListSites.getSelectedIndex());
            
        
    }//GEN-LAST:event_jListSitesValueChanged
    
    private void showSelectedSite(){
        
        if (jListSites.getSelectedValue() instanceof Site){
            saveAllData();
            this.site = (Site) jListSites.getSelectedValue();
            fillSiteFields(this.site);
        } else {
            emptySiteFields();
        }
        
        
        Storage.getPhaseFormAction().clearFields();
        Storage.getActionFormAction().clearFields();
    }
    
    private void jButtonAddSiteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonAddSiteActionPerformed
        addSite();
        fillSiteList();
        //fillSiteComboBox();
    }//GEN-LAST:event_jButtonAddSiteActionPerformed
    
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButtonAddActions;
    private javax.swing.JButton jButtonAddPhases;
    private javax.swing.JButton jButtonAddSite;
    private javax.swing.JButton jButtonAddSite1;
    private javax.swing.JButton jButtonAddZones;
    private javax.swing.JButton jButtonDelActions;
    private javax.swing.JButton jButtonDelPhases;
    private javax.swing.JButton jButtonDelSite;
    private javax.swing.JButton jButtonDelZones;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JList jListActions;
    private javax.swing.JList jListPhases;
    private javax.swing.JList jListSites;
    private javax.swing.JList jListZones;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JScrollPane jScrollPane5;
    private javax.swing.JTextArea jTextAreaDescription;
    private javax.swing.JTextField jTextFieldAbbreviation;
    private javax.swing.JTextField jTextFieldAcronym;
    private javax.swing.JTextField jTextFieldArea;
    private javax.swing.JTextField jTextFieldCountry;
    private javax.swing.JTextField jTextFieldId;
    private javax.swing.JTextField jTextFieldName;
    private javax.swing.JTextField jTextFieldRegion;
    private javax.swing.JTextField jTextFieldToponym;
    private javax.swing.JTextField jTextFieldTown;
    // End of variables declaration//GEN-END:variables
    
    private Site site;
    
    /**
     * Gets default instance. Do not use directly: reserved for *.settings files only,
     * i.e. deserialization routines; otherwise you could get a non-deserialized instance.
     * To obtain the singleton instance, use {@link findInstance}.
     */
    public static synchronized SiteFormTopComponent getDefault() {
        if (instance == null) {
            instance = new SiteFormTopComponent();
        }
        return instance;
    }
    
    /**
     * Obtain the SiteFormTopComponent instance. Never call {@link #getDefault} directly!
     */
    public static synchronized SiteFormTopComponent findInstance() {
        TopComponent win = WindowManager.getDefault().findTopComponent(PREFERRED_ID);
        if (win == null) {
            ErrorManager.getDefault().log(ErrorManager.WARNING, "Cannot find SiteForm component. It will not be located properly in the window system.");
            return getDefault();
        }
        if (win instanceof SiteFormTopComponent) {
            return (SiteFormTopComponent)win;
        }
        ErrorManager.getDefault().log(ErrorManager.WARNING, "There seem to be multiple components with the '" + PREFERRED_ID + "' ID. That is a potential source of errors and unexpected behavior.");
        return getDefault();
    }
    
    public int getPersistenceType() {
        return TopComponent.PERSISTENCE_ALWAYS;
    }
    
    public void componentOpened() {
        this.setDisplayName("Sites administrator");
        fillSiteList();
    }
    
    public void componentClosed() {
        saveAllData();
        Storage.getPhaseFormAction().close();
        Storage.getActionFormAction().close();
    }
    
    /** replaces this in object stream */
    public Object writeReplace() {
        return new ResolvableHelper();
    }
    
    protected String preferredID() {
        return PREFERRED_ID;
    }
    
    final static class ResolvableHelper implements Serializable {
        private static final long serialVersionUID = 1L;
        public Object readResolve() {
            return SiteFormTopComponent.getDefault();
        }
    }
    
    private void fillSiteList() {
        DefaultListModel sitemodel = new DefaultListModel();
        
        try {
            List list = Site.Inventory.getList();
            TreeSet <Site> sites = new TreeSet<Site>();
            
            Iterator iter2 = list.iterator();
            while(iter2.hasNext()){
                Site site = (Site) iter2.next();
                sites.add(site);
            }
            
            //Ho fiquem en un TreeSet per a tenir la col�lecci� ordenada
            Iterator iter = sites.iterator();
            while (iter.hasNext()){
                sitemodel.addElement(iter.next());
            }
            
        } catch (Exception e1) {
            LoggerProvider.getInstance().log(Level.WARNING,"Exception",e1);
        }
        jListSites.setModel(sitemodel);
        
        Storage.getSiteNavigation().fillSiteComboBox();
    }
    
    private static void addSite(){
        ParameterCollector param = new ParameterCollector();
        Site.Inventory si = new Site.Inventory();
        
        Site site = null;
        try {
            site = si.getNewObject(param);
            site.setId(Site.Inventory.getNewKey());
            site.setName("New Site");
            site.setAcronyn("");
            site.setAbbreviation("");
            site.setToponym("");
            site.setTown("");
            site.setArea("");
            site.setRegion("");
            site.setCountry("");
            site.setDescription("");
            
            si.setObject(site);
            
            
        }catch (Exception e1) {
            LoggerProvider.getInstance().log(Level.WARNING,"Exception",e1);
        }
    }
    
    private void fillSiteFields(Site site){
        jTextAreaDescription.setText(site.getDescription());
        jTextFieldAbbreviation.setText(site.getAbbreviation());
        jTextFieldAcronym.setText(site.getAcronym());
        jTextFieldArea.setText(site.getArea());
        jTextFieldCountry.setText(site.getCountry());
        jTextFieldId.setText(site.getId());
        jTextFieldName.setText(site.getName());
        jTextFieldRegion.setText(site.getRegion());
        jTextFieldToponym.setText(site.getToponym());
        jTextFieldTown.setText(site.getTown());
        
        fillPhaseList();
        fillActionList();
        fillZoneList();
    }
    
    private void emptySiteFields(){
        jTextAreaDescription.setText("");
        jTextFieldAbbreviation.setText("");
        jTextFieldAcronym.setText("");
        jTextFieldArea.setText("");
        jTextFieldCountry.setText("");
        jTextFieldId.setText("");
        jTextFieldName.setText("");
        jTextFieldRegion.setText("");
        jTextFieldToponym.setText("");
        jTextFieldTown.setText("");
        jListPhases.setModel(new DefaultListModel());
        jListZones.setModel(new DefaultListModel());
        jListActions.setModel(new DefaultListModel());
    }
    
    protected void removeSite() {
        //Recupera l'element seleccionat
        Site site = (Site) jListSites.getSelectedValue();
        
        AbstractInventory.deleteObject(site);
        this.site = null;
        fillSiteList();
        
        emptySiteFields();
    }
    
    private void addPhase(){
        if (this.site!=null){
            ParameterCollector param = new ParameterCollector();
            Phase.Inventory pi = new Phase.Inventory();
            
            Date dt = new Date();
            
            try {
                Phase phase = pi.getNewObject(param);
                phase.setId(Phase.Inventory.getNewKey());
                phase.setSite(this.site);
                phase.setName("New phase");
                phase.setDating(new Dating());
                pi.setObject(phase);
            }catch (Exception e1) {
                LoggerProvider.getInstance().log(Level.WARNING,"Exception",e1);
            }
        }
    }
    
    private void fillPhaseList() {
        DefaultListModel phaseModel = new DefaultListModel();
        
        if (this.site != null){
            try {
                List list = Phase.Inventory.getList(this.site);
                TreeSet <Phase> phases = new TreeSet<Phase>();
                //java.util.Collections.sort(list);
                LoggerProvider.getInstance().fine("list size: "+list.size());
                
                Iterator iter2 = list.iterator();
                while(iter2.hasNext()){
                    //Phase phase = (Phase) iter2.next();
                    //phaseModel.addElement(iter2.next());
                    phases.add((Phase) iter2.next());
                    
                }
                
                LoggerProvider.getInstance().fine("phases size: "+phases.size());
                
                //Ho fiquem en un TreeSet per a tenir la col�lecci� ordenada
                Iterator iter = phases.iterator();
                while (iter.hasNext()){
                    phaseModel.addElement(iter.next());
                }
                
            } catch (Exception e1) {
                LoggerProvider.getInstance().log(Level.WARNING,"Error",e1);
            }
        }
        jListPhases.setModel(phaseModel);
    }
    
    private void addAction(){
        if (this.site!=null){
            ParameterCollector param = new ParameterCollector();
            Action.Inventory ai = new Action.Inventory();
            
            
            
            try {
                Action action = ai.getNewObject(param);
                action.setId(Action.Inventory.getNewKey());
                action.setName("New Action");
                action.setSite(this.site);
                action.setObjectives("");
                action.setStartDate(new Date());
                action.setEndDate(new Date());
                ai.setObject(action);
                
                
            }catch (Exception e1) {
                LoggerProvider.getInstance().log(Level.WARNING,"Exception creating new Action",e1);
            }
        }
    }
    
    private void fillSiteComboBox(){
        Storage.getSiteNavigation().fillSiteComboBox();
    }
    
    private void fillZoneList() {
        DefaultListModel zonesModel = new DefaultListModel();
        Zone zone;
        

        if (this.site != null) {
            try {
                List list = Zone.Inventory.getList(this.site);
                TreeSet<Zone> zones = new TreeSet<Zone>();
                //java.util.Collections.sort(list);
                LoggerProvider.getInstance().fine("list size: " + list.size());
     
                Iterator iter2 = list.iterator();
                while(iter2.hasNext()){
                    zones.add((Zone) iter2.next());
                }
                
                LoggerProvider.getInstance().fine("phases size: "+zones.size());
                
                //Ho fiquem en un TreeSet per a tenir la col�lecci� ordenada
                Iterator iter = zones.iterator();
                while (iter.hasNext()){
                    zone = (Zone) iter.next();
                    zonesModel.addElement(zone);
                }
                
            } catch (Exception e1) {
                LoggerProvider.getInstance().log(Level.WARNING,"Error",e1);
            }
        }
        jListZones.setModel(zonesModel);
    } 
    private void fillActionList() {
        DefaultListModel actionsModel = new DefaultListModel();
        Action action;
        
        if (this.site != null){
            try {
                List list = Action.Inventory.getList(this.site);
                TreeSet <Action> actions = new TreeSet<Action>();
                //java.util.Collections.sort(list);
                LoggerProvider.getInstance().fine("list size: "+list.size());
                
                Iterator iter2 = list.iterator();
                while(iter2.hasNext()){
                    actions.add((Action) iter2.next());
                }
                
                LoggerProvider.getInstance().fine("phases size: "+actions.size());
                
                //Ho fiquem en un TreeSet per a tenir la col�lecci� ordenada
                Iterator iter = actions.iterator();
                while (iter.hasNext()){
                    action = (Action) iter.next();
                    actionsModel.addElement(action);
                }
                
            } catch (Exception e1) {
                LoggerProvider.getInstance().log(Level.WARNING,"Error",e1);
            }
        }
        jListActions.setModel(actionsModel);
    }
}
